#!/usr/bin/python3
# -*- coding:utf-8 -*-
""""
   @Author: 叶建伟
   @Email: yejw46507@hundsun.com
   @Time: 2023/6/26 15:10
   @File: dingding.py
"""
from datetime import datetime

from dingtalkchatbot.chatbot import DingtalkChatbot



# 发送钉钉消息
def send_dingtalk_message(webhook,secret,content):
    dogBOSS = DingtalkChatbot(webhook, secret)
    red_msg = '<font color="#FFA500">级别:警告</font>'
    now_time = datetime.now().strftime('%Y.%m.%d %H:%M:%S')
    url = 'https://dev.hundsun.com/frameV2/cicd/artifacts'
    dogBOSS.send_markdown(
        title=f'来自李导善意的提醒',
        text=f'### **sql检测通知**\n'
             f'**{red_msg}**\n\n'
             f'**检测结果:**  {content}**\n\n'
             f'**发送时间:**  {now_time}\n\n'
             f'**制品地址:**[点击跳转]({url}) \n',
        is_at_all=False)



if __name__ == "__main__":
    # 获取dingtalk token url
    webhook ='https://oapi.dingtalk.com/robot/send?access_token=cc5d5ab5c87374d10af92aacfe02316573789ba1ded3717e607c7106aaab96f6'
    secret = 'SEC6240f8c7b5d9e3389aba0c78205e030537e349e13f43d7cb65e7366edad655d7'
    content = "/DCT4.0-CSAML-V202301-00-000-20230420/next/基金行业_20220418_20230620.sql<脚本中存在insert into tamlrule但C_VISIBLE != 0的情况,实际情况:C_VISIBLE = 1>"
    mobile_list = []
    send_dingtalk_message(webhook,secret,content)

